import jsonpath


def assert_res(assertRes,res):
    '''
    断言处理
    :param assertRes: excel中的断言表达式，&.code=0;&.msg=success
    :param res: 请求返回结果 {‘code’:200,'msg':success}
    :return:
    '''

    status = 'pass'
    for i in assertRes.split(';'):
        if i.strip:
            expr = i.split('=')[0]
            actual_value = jsonpath.jsonpath(res,expr)[0]
            except_value = i.split('=')[1]
            if str(actual_value) != except_value:
                status = 'fail'
                return status
    return status

if __name__ == '__main__':
    assertRes = '$.code=1;$.msg=success'
    res = {'code':0,'msg':'success'}
    result = assert_res(assertRes,res)
    print(result)